﻿using SIG.Model.Blogs;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace SIG.Data.Mapping
{
    public class PostMap : EntityTypeConfiguration<Post>
    {
        public PostMap()
        {
            this.HasKey(p => p.Id);

            this.Property(p => p.Id)
                .HasColumnName("Id")
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.ToTable("PostSet");

            this.Property(p => p.Title).HasMaxLength(100).IsRequired();
            this.Property(p => p.Body).IsMaxLength();
            this.Property(p => p.CategoryId).IsRequired();
            this.Property(p => p.ViewCount).IsRequired();
            this.Property(p => p.CreatedDate).IsRequired().HasColumnType("datetime");
            this.Property(p => p.CreatedBy).HasMaxLength(50);
            this.Property(p => p.UpdatedDate).IsOptional().HasColumnType("datetime");
            this.Property(p => p.UpdatedBy).IsOptional().HasMaxLength(50);

            this.HasRequired(p => p.PostCategory)
            .WithMany(h=>h.Posts)
            .HasForeignKey(p => p.CategoryId);  
        }
    }
}
